package com.ohs.bo.action;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

import com.ohs.bll.service.AccountService;
import com.ohs.bll.util.Constant;
import com.ohs.bo.form.LoginUser;
import com.ohs.fo.action.AbstractAction;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ValidationAware;

public class LoginAction extends AbstractAction {

	private String username;
	
	private String password;
	
	private AccountService accountService;
	
	public void validate() {
		clearErrorsAndMessages();
	}
	
	public String show() throws Exception {
		return "success";
	}

	public String loginSubmit() throws Exception {
		/*if (accountService.checkLogin(username, password)) {
			LoginUser loginUser = new LoginUser();
			loginUser.setUsername(username);
			HttpServletRequest request = ServletActionContext.getRequest();
			request.getSession().setAttribute(Constant.USER_ACCOUNT, loginUser);
			request.getSession().setAttribute(Constant.USER_NAME, username);
			return "success";
		} else {
			addActionError("Tên đăng nhập hoặc mật khẩu không đúng.");
			return "input";
		}*/
		return "";
	}

	public String logout() throws Exception {
		ActionContext context = ActionContext.getContext();
		HttpServletRequest request = (HttpServletRequest) context
				.get(ServletActionContext.HTTP_REQUEST);
		HttpSession session = request.getSession(true);
		session.removeAttribute(Constant.USER_ACCOUNT);
		return "success";
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}
	
	public AccountService getAccountService() {
		return accountService;
	}

	public void setAccountService(AccountService accountService) {
		this.accountService = accountService;
	}
}